<?php
namespace app\api\controller;
use think\Controller;
use think\Request;
use think\Session;
use app\base\model\User;
use think\Validate;
use think\Cache;
class BaseC extends Controller{
    protected $userModel;
    protected $userInfo;
    protected $user_id;
   public function __construct(Request $request = null)
   {
       parent::__construct($request);
       $this->userModel    = new User();
       $session_id=$this->request->post('session_id','');
       if(empty($session_id)){
           $msg['message']=checkMsg(LOGIN_ERROR);
           return $msg;
       }
       $this->userInfo=Cache::get($session_id);
       if(!empty($this->userInfo)){
           $this->user_id=$this->userInfo['uid'];
       }
       header("Access-Control-Allow-Origin: *");
   }
    public function upload($checkData){
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 移动到框架应用根目录/public/uploads/ 目录下
        $info = $file->validate($checkData)->move(ROOT_PATH . 'public' . DS . 'uploads');
        if($info){
            $a=$info->getSaveName();
            $imgp= str_replace("\\","/",$a);
            $imgpath='/uploads/'.$imgp;
            $msg['message']=checkMsg(UPLOAD_SUCCESS);
            $msg['path']=$imgpath;
            return $msg;
        }else{
            // 上传失败获取错误信息
            //  echo $file->getError();
            $msg['message']=checkMsg(UPLOAD_FAIL);
            return $msg;
        }
    }
}